package com.atguigu.gulimall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @ClassName GulimallCorsConfiguration
 * @Description TODO
 * @Author free
 * @Date 2024/5/14 10:24
 * @Version 1.0
 **/
@Configuration
public class GulimallCorsConfiguration {
    @Bean
    public CorsWebFilter crorsWebFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsconfiguration = new CorsConfiguration();
        corsconfiguration.addAllowedHeader("*");
        corsconfiguration.addAllowedMethod("*");
        corsconfiguration.addAllowedOrigin("*");
        corsconfiguration.setAllowCredentials(true);
        source.registerCorsConfiguration("/**", corsconfiguration);
        return new CorsWebFilter(source);
    }
}
